<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>进货验收工具</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="进货验收工具">
<link rel="stylesheet" type="text/css" href="<%=path%>/easyui/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/easyui/themes/icon.css">
<script type="text/javascript" src="<%=path%>/easyui/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path%>/easyui/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=path%>/easyui/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<%=path%>/easyui/js/con_isok.js"></script>

</head>
<body class="easyui-layout">

<div data-options="region:'north',border:false" style="padding:2px;">
	<table align="">
		<tr>
			<td>IP地址:</td>
				<td><input id="ip_address_id" class="easyui-validatebox" missingMessage="IP地址为必填项" data-options="required:true,validType: 'isIP'" value="">
			</td>
			<td>出库单号:</td>
			<td><input id="ckd_no_id" class="easyui-numberbox" value=""></td>
			<td colspan="2"><b id="node_name_id"></b></td>
		</tr>
		<tr>
			<td>开始时间:</td>
				<td><input id="begin_time_id" class="easyui-datebox" data-options="required:true,editable:false">
			</td>
			<td>结束时间:</td>
				<td><input id="end_time_id" class="easyui-datebox" data-options="required:true,editable:false">
			</td>
			<td ><b id="node_no_id"></b></td>
			<td ><b id="sys_node_no_id"></b></td>
		</tr>
		<tr>
			<td align="center"><a id="select_btn" href="javascript:void(0);" class="easyui-linkbutton" onclick="select_data1();">查询</a></td>
<%--			<td align="center"><a id="select_btn" href="javascript:void(0);" class="easyui-linkbutton" onclick="upload();">上传</a></td>--%>
			<td align="center"><a id="select_btn" href="javascript:void(0);" class="easyui-linkbutton" onclick="sysnc1();">同步并上传</a></td>
		</tr>
	</table>
</div>

<div data-options="region:'center', border:false" style="padding:2px;">
	<table id="dg" class="easyui-datagrid" data-options="
			url:'<%=path %>/jhsy/index.do',
			fit:true,
			singleSelect:false,
			fitColumns: true,
			border:false,
			onLoadSuccess:onLoadSuccess,
			onClickRow:onClickRow
	">
		<thead>
			<tr>
				<th data-options="field:'manualNo',width:100">手工单号</th>
				<th data-options="field:'deliveryNo',width:100">出库单号</th>
				<th data-options="field:'oilNo',width:100">油品编号</th>
				<th data-options="field:'shift',width:100">班次号</th>
				<th data-options="field:'oilCan',width:50">罐号</th>
				<th data-options="field:'beginTimeb',width:130">卸油开始时间</th>
				<th data-options="field:'endTimeb',width:130">卸油结束时间</th>
				<th data-options="field:'dischargeLoss',width:100">卸油损耗量Vt</th>
				<th data-options="field:'dischargeLossV20',width:100">卸油损耗量V20</th>
				<th data-options="field:'dischargeRate',width:100">卸油损耗率</th>
				<th data-options="field:'dischargeRateV20',width:100">卸油损耗率V20</th>
				<th data-options="field:'dischargeL',width:100">实收升数</th>
				<th data-options="field:'beginOilHeight',width:100">前尺_油高</th>
				<th data-options="field:'beginOilL',width:100">前尺_油体积</th>
				<th data-options="field:'beginV20L',width:100">前尺_V20体积</th>
				<th data-options="field:'beginTemperature',width:100">前尺_温度</th>
				<th data-options="field:'endOilHeight',width:100">后尺_油高</th>
				<th data-options="field:'endOilL',width:100">后尺_油体积</th>
				<th data-options="field:'endV20L',width:100">后尺_V20体积</th>
				<th data-options="field:'endTemperature',width:100">后尺_温度</th>
				<th data-options="field:'endTime',width:140">卸油完成时间</th>
				<th data-options="field:'isDoneJhys',width:100,formatter:formatModel,align:'center'">平台状态</th>
			</tr>
		</thead>
	</table>
</div>



	<script type="text/javascript">
		
		function onClickRow(rowIndex,rowData){
			if(!rowData.endTime){
				$.messager.alert("提示","该条数据未完成进货验收,不能同步!", "error");
				$('#dg').datagrid('unselectRow',rowIndex);
				return;
			}
			
			if(rowData.isDoneJhys == "1"){
				$.messager.alert("提示","该条进货验收数据已经同步完成!", "error");
				$('#dg').datagrid('unselectRow',rowIndex);
				return;
			}
			
		}
	
		function onLoadSuccess(){
			$("#node_name_id").html("");
			$("#node_no_id").html("");
			var ip = $("#ip_address_id").val();
			if(ip){
				$.ajax({
					url: "<%=path %>/jhsy/nodeInfo.do",
					type: "post",
					dataType: "json",
					data:{
						ipAddress:ip
					},
					success:function(data){
						$("#node_name_id").html(data["nodeName"]);
						$("#node_no_id").html("零管代码:" + data["nodeno"]);
						$("#sys_node_no_id").html("管控代码:" + data["sys_nodeno"]);
					}
				});
			}
		}
	
		function formatModel(val,index,row){
			if(val == "1"){
				return "已验收";
			}else if(val == "2"){
				return "被过滤";
			}
			return "未验收";
		}
	
	
		$(function(){
			var myDate = new Date();
			var year = myDate.getFullYear();
			var month = myDate.getMonth() + 1;
			var bday = myDate.getDate()-3;
			var eday = myDate.getDate();
			
			$("#begin_time_id").datebox('setValue', year +"-"+ month + "-" + bday);
			$("#end_time_id").datebox('setValue', year +"-"+ month + "-" + eday);
		});
	
		var isRightIP = false;
	
		$.extend($.fn.validatebox.defaults.rules, {
			isIP : {
				validator : function(value) {
					var ip_rex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
					isRightIP = ip_rex.test(value);
					return isRightIP;
				},
				message : "请输入正确的IP地址."
			}
		});
		
		
		
		function select_data1(){
			if(!isRightIP){
				$.messager.alert("提示","请输入正确的IP地址.", "error");
				return;
			}
			var ipAddress = $("#ip_address_id").val();
			
			isOkCon(ipAddress, "<%=path %>","select_data()");
		}
		
		function select_data() {
			var ipAddress = $("#ip_address_id").val();
			var ckdNo = $("#ckd_no_id").val();
			var beginTime = $("#begin_time_id").datebox('getValue');
			var endTime = $("#end_time_id").datebox('getValue');
			$("#dg").datagrid('load', {
				ipAddress:ipAddress,
				ckdNo:ckdNo,
				beginTime:beginTime,
				endTime:endTime
			});
		}
		
		function upload(){
			var ipAddress = $("#ip_address_id").val();
			$.messager.progress({title: "提示", msg: "正在上传.."});
			$.ajax({
				url: "<%=path %>/jhsy/upload.do",
				type: "post",
				dataType: "json",
				data:{
					ipAddress:ipAddress
				},
				success:function(data){
					//$.messager.alert("提示","OK");
				},
				complete:function(){
			 		$.messager.progress('close');
			 	}
			});
		}
		
		
		function sysnc1(){
			var rows = $("#dg").datagrid("getSelections");
			var ipAddress = $("#ip_address_id").val();
			if(rows.length == 0){
				$.messager.alert("提示","请选择一条数据!", "error");
				return;
			}
			
			isOkCon(ipAddress, "<%=path %>","sysnc()");
		}
		
		function sysnc(){
			
			var rows = $("#dg").datagrid("getSelections");
			var ipAddress = $("#ip_address_id").val();
			if(rows.length == 0){
				$.messager.alert("提示","请选择一条数据!", "error");
				return;
			}
			
			var ckdNoArray = [];
			for(var i = 0; i < rows.length; i++){
				ckdNoArray.push(rows[i].deliveryNo);
			}
			
			$.messager.progress({title: "提示", msg: "正在同步并上传..."});
			$.ajax({
				url: "<%=path %>/jhsy/sysnc.do",
				type: "post",
				dataType: "text",
				data:{
					deliveryNos:JSON.stringify(ckdNoArray),
					ipAddress:ipAddress
				},
				success:function(data){
					if(data == "error"){
						$.messager.alert("提示","该条进货验收数据已经同步完成!", "error");
					}else{
						$.messager.alert("提示","同步成功!", "info");
					}
				},
				complete:function(){
			 		$.messager.progress('close');
					$('#dg').datagrid('reload');
			 	}
			});
		}
		
		
		
		
		
	</script>
</body>
</html>
